<script src="../../../../public/static/admin/dist/js/ajaxfileupload.js"></script>{extend name="common:base" /}


{block name="breadcrumb"}
<h1>
    轮播图管理
    <small>轮播图管理</small>
</h1>
<ol class="breadcrumb">
    <li><a href="{:url('/admin')}"><i class="fa fa-dashboard"></i> 控制台</a></li>
    <li><a href="{:url('/admin/carousel')}">轮播图管理</a></li>
    <li class="active">添加轮播图</li>
</ol>
{/block}


{block name="content"}
<!-- Default box -->

<form action="{:url('/admin/carousel/add')}" method="post" style="display: block;" id="formDocument">
    <div class="row">
        <!-- left column -->
        <div class="col-md-12">
            <!-- Horizontal Form -->
            <div class="box box-info">
                <div class="box-header with-border">
                    <h3 class="box-title">基本信息</h3>
                </div>
                <!-- /.box-header -->
                <!-- form start -->
                <div class="form-horizontal">
                    <div class="box-body">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">标题</label>
                            <div class="col-sm-10">
                                <input type="text" name="title" class="form-control" id="inputTitle" placeholder="标题">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">地址</label>
                            <div class="col-sm-10">
                                <input type="text" name="url" class="form-control" id="inputUrl" placeholder="地址" >
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">图片</label>
                            <div class="col-sm-10">
                                <div class=" upload-box">
                                    <img class="upload-box-img" src="/static/admin/dist/img/upload-pic.png">
                                    <input class="upload-box-input" type="hidden" name="image" >
                                    <input class="upload-input" type="file" id="file" name="file">
                                </div>
                                <p class="help-block">选择一张图片作为封面.</p>
                            </div>

                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">排序</label>
                            <div class="col-sm-10">
                                <input type="text" name="sort" class="form-control" id="inputSort" placeholder="地址" >
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">启用</label>
                            <div class="col-sm-10">
                                <label><input type="checkbox" name="status" class="flat-red" value="1" checked> </label>
                            </div>
                        </div>

                    </div>
                    <!-- /.box-body -->

                    <!-- /.box-footer -->
                </div>
            </div>
            <!-- /.box -->
        </div>
        <!--/.col (right) -->
        <div class="col-sm-12 p10">
            <div class="submit-box p10">
                <button type="submit" class="btn btn-danger">提交</button>
                <button type="button" class="btn btn-default btn-cancel">取消</button>
            </div>
        </div>

    </div>
</form>
<!-- /.box -->
{/block}
{block name="js"}
<script src="/static/admin/dist/js/ajaxfileupload.js"></script>
<!-- CK Editor -->
<script src="/static/admin/bower_components/ckeditor/ckeditor.js"></script>
<script>

    $("#formDocument").validate({
        rules: {
            title: 'required',
            image: 'required',
        },
        messages: {
            title: "请输入标题",
            content: "请上传图片",
        }
    });
    $('.upload-input').change(function () {
        var pDom = $(this).parent();
        $.ajaxFileUpload({
            url: '/admin/upload', //用于文件上传的服务器端请求地址
            secureuri: false, //是否需要安全协议，一般设置为false
            fileElementId: 'file', //文件上传域的ID
            dataType: 'json', //返回值类型 一般设置为json
            success: function (data, status) {
                var path = data.file_path;
                //console.log(_this.parent());
                pDom.find('img.upload-box-img').attr('src',path);
                pDom.find('input.upload-box-input').val(path);
            },
            error: function (data, status, e) {
                alert(e);
            }
        })
    });



</script>
{/block}